<template>
	<a-card :bordered="false">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
		>
<!--			<template #bodyCell="{ column, record }">-->
<!--&lt;!&ndash;				<template v-if="column.dataIndex === 'action'">&ndash;&gt;-->
<!--&lt;!&ndash;					<a-space>&ndash;&gt;-->
<!--&lt;!&ndash;						<a @click="formRef.onOpen(record)" v-if="hasPerm('dhbaEdit')">编辑</a>&ndash;&gt;-->
<!--&lt;!&ndash;					</a-space>&ndash;&gt;-->
<!--&lt;!&ndash;				</template>&ndash;&gt;-->
<!--			</template>-->
		</s-table>
	</a-card>
	<ImportModel ref="importModelRef" />
	<Form ref="formRef" @successful="tableRef.refresh()" />
</template>

<script setup name="dhba">
	import { cloneDeep } from 'lodash-es'
	import Form from './form.vue'
	import ImportModel from './importModel.vue'
    import downloadUtil from '@/utils/downloadUtil'
	import dhbaApi from '@/api/biz/dhbaApi'
	const tableRef = ref()
	const importModelRef = ref()
	const formRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const columns = [
		{
			title: '账号',
			dataIndex: 'username'
		},
		{
			title: '密码',
			dataIndex: 'password'
		},
		{
			title: '操作',
			dataIndex: 'action',
			width: 100,
			customRender: ({ record }) => {
				return h('a', {
					onClick: () => {
						formRef.value.onOpen(record)
					}
				}, '编辑')
			}
		},
	]
	// 操作栏通过权限判断是否显示
  // columns.push({
  //   title: '操作',
  //   dataIndex: 'action',
  //   align: 'center',
  //   width: 150
  // })
	const selectedRowKeys = ref([])
	// 列表选择配置
	const options = {
		// columns数字类型字段加入 needTotal: true 可以勾选自动算账
		alert: {
			show: true,
			clear: () => {
				selectedRowKeys.value = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}
	const loadData = (parameter) => {
		return dhbaApi.dhbaPage(parameter).then((data) => {
			return data
		})
	}
	// 重置
	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
	// 删除
	const deleteDhba = (record) => {
		let params = [
			{
				id: record.id
			}
		]
		dhbaApi.dhbaDelete(params).then(() => {
			tableRef.value.refresh(true)
		})
	}
	// 导出
    const exportData = () => {
        if (selectedRowKeys.value.length > 0) {
            const params = selectedRowKeys.value.map((m) => {
                return {
                    id: m
                }
            })
            dhbaApi.dhbaExport(params).then((res) => {
                downloadUtil.resultDownload(res)
            })
        } else {
            dhbaApi.dhbaExport([]).then((res) => {
                downloadUtil.resultDownload(res)
            })
        }
    }
	// 批量删除
	const deleteBatchDhba = (params) => {
		dhbaApi.dhbaDelete(params).then(() => {
			tableRef.value.clearRefreshSelected()
		})
	}
</script>
